import {AJAX} from "./ajax.js";
import {URL} from "../router/config.js";

export let removeAllChild = function (element) {
    while (element.firstChild) {
        element.removeChild(element.firstChild);
    }
}, randomColor = function () {
    const r = Math.floor(Math.random() * 255);
    const g = Math.floor(Math.random() * 255);
    const b = Math.floor(Math.random() * 255);
    let a = Math.random();
    a = a < 0.5 ? 1 - a : a;
    return 'rgba(' + r + ',' + g + ',' + b + ',' + a + ')';
}, classContainColor = function (className) {
    let colors = {
        primary: "#3460f3",
        info: "#5de5d8",
        warning: "#d1ba46",
        error: "#b74631",
        danger: "#a9304c",
        success: "#4fc189",
        normal: "#3c4341",
        unset: "#009688"
    }
    if (className.indexOf("primary") > 0) {
        return colors.primary;
    }
    if (className.indexOf("info") > 0) {
        return colors.info;
    }
    if (className.indexOf("warning") > 0) {
        return colors.warning;
    }
    if (className.indexOf("error") > 0) {
        return colors.error;
    }
    if (className.indexOf("danger") > 0) {
        return colors.danger;
    }
    if (className.indexOf("success") > 0) {
        return colors.success;
    }
    if (className.indexOf("normal") > 0) {
        return colors.normal;
    }
    return colors.unset;
}, newTagLoad = function (url) {
    window.location.href = url;
}, pageIncludeLoad = function (url) {
    AJAX.get({
        url: url,
        success: function (data) {
            let element = document.querySelector("#content");
            removeAllChild(element);
            element.innerHTML = data;
        }
    })
}, loadSvgToHtml = function () {
    AJAX.get({
        url: URL.HOST_URL() + URL.PROJECT_SVGS_CONTENT,
        success: function (data) {
            let element = document.querySelector("body");
            element.innerHTML += data;
        }
    })
}, languageKey = {
    "c": "clion",
    "c++": "clion",
    "java": "intellij-idea",
    "sql": "datagrip",
    "go": "goland",
    "php": "phpstorm",
    "python": "pycharm",
    "c#": "rider",
    "ruby": "rubymine",
    "html": "webstorm",
    "javascript": "webstorm",
    "css": "webstorm",
    "kotlin": "kotlin",
    "rust": "intellij-idea",
    "swift": "appcode",
    "other": "toolbox"
}
